package ltd.sshine.websocket.Config;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.util.WebAppRootListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

@Configuration
@EnableWebSocket
public class WebConfig implements ServletContextInitializer {
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.addListener(WebAppRootListener.class);
        //限制大小5m
        servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", String.valueOf(1024*1024*5));
        servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize",String.valueOf(1024*1024*5));
    }
}
